package com.sgb.zhaocai.viewmodel;

import androidx.lifecycle.ViewModel;

import com.sgb.zhaocai.base.BaseApi;
import com.sgb.zhaocai.entity.MarketPersonalEntitly;
import com.sgb.zhaocai.view.fragment.PickMarketPersonalFragment;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.base.model.entity.ListResponse;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PickMarketPersonalModel extends ViewModel {
    PickMarketPersonalFragment fragment;
    private int page = 1;

    public void setActivity(PickMarketPersonalFragment pickMarketPersonalFragment) {
        this.fragment = pickMarketPersonalFragment;
    }
    /**
     * 市场客户-个人列表
     */
    public void getFindPersonalUserByName(boolean isLoadMore,String name) {
        page = isLoadMore? page+1:1;
        Map map = new HashMap();
        map.put("limit","20");
        map.put("page",page);
        map.put("name",name);
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中", 0, true, null).setCanceledOnTouchOutside(false);
        BaseApi.getApi().getFindPersonalUserByName(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<MarketPersonalEntitly>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<MarketPersonalEntitly>>> data) {
                DialogHelper.dismissProgressDialog();
                if (data.getState().equals(BaseApi.RESPONSE_OK)){
                  /*  isLastPage = data.getData().getCurrentPage() >= data.getData().getTotal();*/
                    for (MarketPersonalEntitly memberCompanyEntitly : data.getData().getList()) {
                        memberCompanyEntitly.setCheck(false);
                    }
                    fragment.setFindPersonalUserByName(data.getData().getList(),data.getData().getTotal());
                }else {
                    MToast.showToast(fragment.getActivity(),data.getMsg());
                }
            }
        });
    }
}
